package com.shm.singlecamera.Utils;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;

public class AnimUtils {

    private static AnimatorSet currentAnim;
    public static AnimatorSet buttonScaleOut(View view, float min, float max){
        // 创建一个AnimatorSet来同时播放多个动画
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 放大动画
                ObjectAnimator.ofFloat(view, "scaleX", min, max),
                ObjectAnimator.ofFloat(view, "scaleY", min, max),
                // 透明度动画
                ObjectAnimator.ofFloat(view, "alpha", 1f, 0f)
        );
        currentAnim.setInterpolator(new LinearInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(450);
        currentAnim.start();

        return currentAnim;
    }



    public static AnimatorSet buttonScaleIn(View view, float min, float max){
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 放大动画
                ObjectAnimator.ofFloat(view, "scaleX", max, min),
                ObjectAnimator.ofFloat(view, "scaleY", max, min),
                // 透明度动画
                ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)
        );
        currentAnim.setInterpolator(new LinearInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(450);
        currentAnim.start();

        return currentAnim;
    }

    public static void viewFadeOut(View view){
        // 创建一个AnimatorSet来同时播放多个动画
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 透明度动画
                ObjectAnimator.ofFloat(view, "alpha", 1f, 0.0f)

        );
        currentAnim.setInterpolator(new AccelerateInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(1000);
        currentAnim.start();

    }

    public static void viewFadeIn(View view){
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 透明度动画
                ObjectAnimator.ofFloat(view, "alpha", 0.0f, 1f)

        );
        currentAnim.setInterpolator(new AccelerateInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(1000);
        currentAnim.start();

    }


    public static AnimatorSet buttonXIn(View view){
        // 创建一个AnimatorSet来同时播放多个动画
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 透明度动画
                ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f)
        );
        currentAnim.setInterpolator(new LinearInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(250);
        currentAnim.start();

        return currentAnim;
    }

    public static AnimatorSet buttonXOut(View view){
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 透明度动画
                ObjectAnimator.ofFloat(view, "scaleX", 0f, 1f)
        );
        currentAnim.setInterpolator(new LinearInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(250);
        currentAnim.start();

        return currentAnim;
    }

    public static AnimatorSet wheelRotateIn(View view){
        // 创建一个AnimatorSet来同时播放多个动画
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 透明度动画
                ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)
        );
        currentAnim.setInterpolator(new LinearInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(450);
        currentAnim.start();

        return currentAnim;
    }

    public static AnimatorSet wheelRotateOut(View view){
        // 创建一个AnimatorSet来同时播放多个动画
        currentAnim = new AnimatorSet();
        currentAnim.playTogether(
                // 透明度动画
                ObjectAnimator.ofFloat(view, "alpha", 1f, 0f)
        );
        currentAnim.setInterpolator(new LinearInterpolator());

        // 设置动画持续时间为100ms
        currentAnim.setDuration(450);
        currentAnim.start();

        return currentAnim;
    }
}
